#include "Common.fxh"

#define NUM_CASCADES 3

cbuffer cbPerObject
{
	float4x4 gWorld_CascadeViewProj[NUM_CASCADES];
};

struct VS_IN
{
	float3 posL     : POSITION;
	float3 normalL  : NORMAL0;
	float3 tangentL : TANGENT0;
	float2 texCoord : TEXCOORD0;
};

struct VS_OUT
{
	float3 posL : POSITION0;
};

struct GS_OUT  
{  
	float4 posS  : SV_POSITION;  
	uint rtIndex : SV_RenderTargetArrayIndex;  
};  

VS_OUT VS(VS_IN vIn)
{
	VS_OUT vOut;
	vOut.posL = vIn.posL;
	return vOut;
}

[maxvertexcount(NUM_CASCADES * 3)]  
void GS(triangle VS_OUT In[3], inout TriangleStream<GS_OUT> triStream)  
{  
	for(int cascade = 0; cascade < NUM_CASCADES; cascade++)  
	{  
		GS_OUT Out;  
		
		for(int vertex = 0; vertex < 3; vertex++)  
		{   
			Out.rtIndex = cascade;   
			Out.posS = mul(float4(In[vertex].posL, 1.0f), gWorld_CascadeViewProj[cascade]);  
			triStream.Append(Out);  
		}  
		triStream.RestartStrip();  
	}  
}  

technique11 tech
{
	pass P0
	{
		SetVertexShader( CompileShader( vs_5_0, VS() ) );
		SetGeometryShader( CompileShader( gs_5_0, GS() ) );
		SetPixelShader( NULL );
		
		SetDepthStencilState(DepthOn, 0);
		SetBlendState( NoBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
		SetRasterizerState(CullFront);
	}
}
